package t1009;

import java.util.Scanner;

/**
 * @姓名 张东升
 * @日期 2025年04月2025/4/6日、
 * 1 2 42 2 3 12 23 0 5
 */
public class Main {

    public static int ch;


    public static void main(String[] args) {
        Node intHead = new Node();
        Node stringHead = new Node();
        Scanner scanner = new Scanner(System.in);
        createInt(intHead, scanner);
        createString(stringHead, scanner);
        display(intHead, false);
        // 被是3的倍数就加ch
        addCh(intHead);
        display(intHead, false);
        reserve(stringHead);
        display(stringHead, true);
    }


    public static void addCh(Node head) {
        Node node = head.next;
        while (node != null) {
            if (node.data % 3 != 0) {
                node.data += ch;
            }
            node = node.next;
        }
    }

    public static void createInt(Node head, Scanner scanner) {
        Node node = head;
        int n = scanner.nextInt();
        while (n != 0) {
            node.next = new Node(n, null);
            n = scanner.nextInt();
            node = node.next;
        }
        ch = scanner.nextInt();

    }

    public static void createString(Node head, Scanner scanner) {
        int n = scanner.nextInt();
        Node node = head;
        String str = scanner.next();
        for (int i = 0; i < n; i++) {
            node.next = new Node(str.charAt(i), null);
            node = node.next;
        }
    }

    public static void reserve(Node head) {
        Node prev = null;
        Node current = head.next;
        Node next = null;
        while (current != null) {
            next = current.next;
            current.next = prev;
            prev = current;
            current = next;
        }
        head.next = prev;
    }

    public static void display(Node head, boolean isChar) {
        Node next = head.next;
        System.out.print("Data:");
        if (isChar) {
            while (next != null) {
                System.out.printf("%c", next.data);
                System.out.print(" ");
                next = next.next;
            }
        } else {
            while (next != null) {
                System.out.print(next.data + " ");
                next = next.next;
            }
        }

        System.out.println();
    }


}

class Node {
    public int data;
    public
    Node next;

    public Node() {
    }

    public Node(int data, Node next) {
        this.data = data;
        this.next = next;
    }
}